package com.platform.util;

import com.alibaba.fastjson.JSONObject;
import com.platform.entity.Tree;
import com.platform.util.wechat.MD5;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author xiao liang
 * @version V1.0
 * @Package com.platform.util
 * @Title: TFAddressUtils
 * @Description: TODO
 * @date 2020/3/14 21:42
 */
public class TFAddressUtils {

  public static final String SEREET_KEY = "3nNYXhomxTzdZcRj0MElzS1N6a1PHUh";

  public static final String KEY = "U7FBZ-AJFCD-C6X43-PMG2Y-WJ2EH-2WFDQ";

  public static final String PREFIX = "https://apis.map.qq.com";

  //本接口提供由地址描述到所述位置坐标的转换，与逆地址解析的过程正好相反。
  public static final String GET_LOCATION = "/ws/geocoder/v1";

  //本服务用于单起点到多终点，或多起点到单终点的路线距离（非直线距离）计算：mode计算方式：driving（驾车）、walking（步行）
  //默认：driving
  public static final String GET_DISTANCE = "/ws/distance/v1";

  //构造参数，字典排序
  public static TreeMap<String, Object> getParamInstance() {
    return new TreeMap<String, Object>(new Comparator<String>() {
      @Override
      public int compare(String o1, String o2) {
        return o1.compareTo(o2);
      }
    });
  }



  public static String getRequestUrl(StringBuilder url, TreeMap<String, Object> params) {
    params.put("key", KEY);
//    url.append("?key=" + KEY + "&");
    url.append("?");
    params.forEach((param, value) -> {
      url.append(param + "=" + value + "&");
    });

    if (params.size() >= 1) {
      url.deleteCharAt(url.length() - 1);
    }
    String result = (url.toString() + SEREET_KEY);
    String sig = MD5.getMessageDigest(result).toLowerCase();
    return PREFIX + (url.append("&sig=" + sig).toString());

  }





}
